﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Chaos.messages
{
    class process_model_appinfo : message
    {

        stream.streamable m_appinfo = new model.appinfo();
        public model.appinfo AppInfo
        {
            get { return m_appinfo as model.appinfo; }
            set { m_appinfo = value; }
        }

        public override void process(context in_context)
        {
            ProcessModelAppInfo e = new ProcessModelAppInfo();
            e.AppInfo = AppInfo;
            System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
                new OnProcessModelAppInfoDelegate(OnProcessModelAppInfoUIThread), e);            
        }

        public override void serialize(stream.stream in_Stream)
        {
            in_Stream.begin("process_model_appinfo")
                .serialize("info", ref m_appinfo)
            .end();
        }

        public class ProcessModelAppInfo : EventArgs
        {
            public model.appinfo AppInfo { get; set; }            
            public ProcessModelAppInfo()
            {
            }
        };
        public delegate void OnProcessModelAppInfoDelegate(ProcessModelAppInfo e);

        public void OnProcessModelAppInfoUIThread(ProcessModelAppInfo e)
        {
            model.appinfo appinfo = System.Windows.Application.Current.FindResource("model_appinfo") as model.appinfo;

            MemoryStream ms = new MemoryStream();
            stream.ostream_xml os = new stream.ostream_xml();
            os.open(ms);
            m_appinfo.serialize(os);
            os.close();

            ms.Seek(0, SeekOrigin.Begin);
            messages.factory f = new messages.factory();
            stream.istream_xml xs = new stream.istream_xml(f);
            xs.open(ms);
            appinfo.serialize(xs);
            xs.close();
            ms.Close();
        }


    }
}
